﻿using System;
namespace Producers.Kis.Xtee.Riik.Ee.Producer.Kis {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="ClaimBase_ClaimData", Namespace="http://producers.kis.xtee.riik.ee/producer/kis", Target=typeof(ClaimBaseClaimData))]
    public class ClaimBaseClaimDataSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IClaimBaseClaimData clazz;
        
        public ClaimBaseClaimDataSerializer(IClaimBaseClaimData clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (clazz.ObjectNumber!=null) {
                Writer.WriteStartElement("ObjectNumber");
                Writer.WriteTypeAttribute("http://producers.kis.xtee.riik.ee/producer/kis", "NonEmptyString");
                Writer.WriteString(clazz.ObjectNumber.ToString());
                Writer.WriteEndElement();
            }
            Writer.WriteStartElement("Type");
            if (clazz.Type!=null) {
                Writer.WriteTypeAttribute("http://producers.kis.xtee.riik.ee/producer/kis", "ClaimBaseType");
                Writer.WriteString(clazz.Type.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Type");
            }
            Writer.WriteEndElement();
            if (clazz.BeginningDate!=null) {
                Writer.WriteStartElement("BeginningDate");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.BeginningDate))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.EndDate!=null) {
                Writer.WriteStartElement("EndDate");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.EndDate))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.ObjectDate!=null) {
                Writer.WriteStartElement("ObjectDate");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.ObjectDate))).ToString());
                Writer.WriteEndElement();
            }
            Writer.WriteStartElement("ClaimBaseID");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.ClaimBaseID))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("IsProof");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "boolean");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdBoolean(((bool)(clazz.IsProof))).ToString());
            Writer.WriteEndElement();
            if (clazz.LiikDescription!=null) {
                Writer.WriteStartElement("LiikDescription");
                Writer.WriteTypeAttribute("http://producers.kis.xtee.riik.ee/producer/kis", "NonEmptyString");
                Writer.WriteString(clazz.LiikDescription.ToString());
                Writer.WriteEndElement();
            }
            Writer.WriteStartElement("Liik");
            if (clazz.Liik!=null) {
                Writer.WriteTypeAttribute("http://producers.kis.xtee.riik.ee/producer/kis", "ClaimBaseFavour_ClaimData");
                Writer.WriteString(clazz.Liik.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Liik");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="ObjectNumber") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ClaimBase_ClaimData>ObjectNumber");
                }
                clazz.ObjectNumber = new global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.NonEmptyString(Reader.ReadElementString("ObjectNumber"));
            }
            if (Reader.LocalName=="Type") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ClaimBase_ClaimData>Type");
                }
                clazz.Type = new global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.ClaimBaseType(Reader.ReadElementString("Type"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ClaimBase_ClaimData>Type", Reader.LocalName);
            }
            if (Reader.LocalName=="BeginningDate") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ClaimBase_ClaimData>BeginningDate");
                }
                clazz.BeginningDate = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("BeginningDate")).Value;
            }
            if (Reader.LocalName=="EndDate") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ClaimBase_ClaimData>EndDate");
                }
                clazz.EndDate = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("EndDate")).Value;
            }
            if (Reader.LocalName=="ObjectDate") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ClaimBase_ClaimData>ObjectDate");
                }
                clazz.ObjectDate = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("ObjectDate")).Value;
            }
            if (Reader.LocalName=="ClaimBaseID") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ClaimBase_ClaimData>ClaimBaseID");
                }
                clazz.ClaimBaseID = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("ClaimBaseID")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ClaimBase_ClaimData>ClaimBaseID", Reader.LocalName);
            }
            if (Reader.LocalName=="IsProof") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ClaimBase_ClaimData>IsProof");
                }
                clazz.IsProof = new global::Xtee.Core.Schema.XsdBoolean(Reader.ReadElementString("IsProof")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ClaimBase_ClaimData>IsProof", Reader.LocalName);
            }
            if (Reader.LocalName=="LiikDescription") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ClaimBase_ClaimData>LiikDescription");
                }
                clazz.LiikDescription = new global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.NonEmptyString(Reader.ReadElementString("LiikDescription"));
            }
            if (Reader.LocalName=="Liik") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ClaimBase_ClaimData>Liik");
                }
                clazz.Liik = new global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.ClaimBaseFavourClaimData(Reader.ReadElementString("Liik"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ClaimBase_ClaimData>Liik", Reader.LocalName);
            }
        }
    }
}
